//
//  HMWelcomeViewController.m
//  weibo
//
//  Created by apple on 2016/11/17.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "HMWelcomeViewController.h"
#import "HMAccountViewModel.h"
@interface HMWelcomeViewController ()
@property(nonatomic,strong)UIImageView *iv_icon;
@property(nonatomic,strong) UILabel *lb_name;
@end

@implementation HMWelcomeViewController
-(UIImageView *)iv_icon{
    if (!_iv_icon) {
        _iv_icon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar_default_big"]];
    }
    return _iv_icon;
}
-(UILabel *)lb_name{
    if (!_lb_name) {
        _lb_name = [[UILabel alloc]initWithText:@"大大大" textColor:[UIColor darkGrayColor] textAlignment:NSTextAlignmentCenter fontSize:16];
    }
    return _lb_name;
}
#pragma mark
#pragma mark - 入口
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupUI];
    [self changeUserMessage];
}
-(void)setupUI{
    [self.view addSubview:self.iv_icon];
    [self.view addSubview:self.lb_name];
    
    [_iv_icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).offset(-120);
        make.centerX.equalTo(self.view);
    }];
    [_lb_name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_iv_icon.mas_bottom).offset(10);
        make.centerX.equalTo(_iv_icon);
    }];
    _lb_name.alpha = 0;
    _iv_icon.layer.cornerRadius = self.iv_icon.bounds.size.width/2;
    _iv_icon.clipsToBounds = YES;
}
-(void)changeUserMessage{
  self.lb_name.text = [HMAccountViewModel shared].accountModel.name;
    NSURL *url = [NSURL URLWithString:[HMAccountViewModel shared].accountModel.avatar_large];
    [self.iv_icon sd_setImageWithURL:url];
}

#pragma mark
#pragma mark - 开始动画
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self startAnimator];
}
-(void)startAnimator{
    CGFloat offset = ScreenHeight - 120 -self.iv_icon.bounds.size.height;
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:7 options:UIViewAnimationOptionCurveEaseIn animations:^{
       
        [self.iv_icon mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.view).offset(-offset);
        }];
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:0.5 animations:^{
            self.lb_name.alpha = 1;
        } completion:^(BOOL finished) {
            
            [[NSNotificationCenter defaultCenter]postNotificationName:ChooseNotificationController object:nil];
            
        }];
        
    }];
}


@end
